home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / tcl / xf2.3-p / xf2 / xf2.3 / src / xfinputBox.tcl < prev    next >
Encoding:
Text File  |  1993-11-20  |  12.1 KB  |  319 lines

  1. # XFNoParsing
  2. # Program: template
  3. # Description: input box
  4. #
  5. # $Header: xfinputBox.tcl[2.3] Wed Mar 10 12:06:25 1993 garfield@garfield frozen $
  6.  
  7. global xfInputBox
  8. set xfInputBox(activeBackground) ""
  9. set xfInputBox(activeForeground) ""
  10. set xfInputBox(anchor) n
  11. set xfInputBox(background) ""
  12. set xfInputBox(erase) 1
  13. set xfInputBox(font) ""
  14. set xfInputBox(foreground) ""
  15. set xfInputBox(justify) center
  16. set xfInputBox(scrollActiveForeground) ""
  17. set xfInputBox(scrollBackground) ""
  18. set xfInputBox(scrollForeground) ""
  19. set xfInputBox(toplevelName) .xfInputBox
  20.  
  21. proc XFInputBoxOne {{xfInputBoxMessage "Input box:"} {xfInputBoxCommandOk ""} {xfInputBoxCommandCancel ""} {xfInputBoxGeometry 350x150} {xfInputBoxTitle "Input box"}} {# xf ignore me 5
  22. ##########
  23. # Procedure: XFInputBoxOne
  24. # Description: show input box with one text line
  25. # Arguments: {xfInputBoxMessage} - message to display
  26. #            {xfInputBoxCommandOk} - the command to call after ok
  27. #            {xfInputBoxCommandCancel} - the command to call after cancel
  28. #            {xfInputBoxGeometry} - the geometry for the window
  29. #            {xfInputBoxTitle} - the title for the window
  30. # Returns: The entered text
  31. # Sideeffects: none
  32. # Notes: there exist also a function called:
  33. #          XFInputBoxMulti - to enter multiline text
  34. ##########
  35. #
  36. # global xfInputBox(activeBackground) - active background color
  37. # global xfInputBox(activeForeground) - active foreground color
  38. # global xfInputBox(anchor) - anchor for message box
  39. # global xfInputBox(background) - background color
  40. # global xfInputBox(erase) - erase previous text
  41. # global xfInputBox(font) - message font
  42. # global xfInputBox(foreground) - foreground color
  43. # global xfInputBox(justify) - justify for message box
  44. # global xfInputBox(scrollActiveForeground) - scrollbar active background color
  45. # global xfInputBox(scrollBackground) - scrollbar background color
  46. # global xfInputBox(scrollForeground) - scrollbar foreground color
  47. # global xfInputBox(scrollSide) - side where scrollbar is located
  48. # global xfInputBox(toplevelName) - the toplevel name
  49. # global xfInputBox(toplevelName,inputOne) - the text in the entry widget
  50.  
  51.   global xfInputBox
  52.  
  53.   if {$xfInputBox(erase)} {
  54.     set xfInputBox($xfInputBox(toplevelName),inputOne) ""
  55.   } {
  56.     if {![info exists xfInputBox($xfInputBox(toplevelName),inputOne)]} {
  57.       set xfInputBox($xfInputBox(toplevelName),inputOne) ""
  58.     }
  59.   }
  60.   XFInputBoxInternal $xfInputBoxMessage $xfInputBoxCommandOk $xfInputBoxCommandCancel $xfInputBoxGeometry $xfInputBoxTitle 1
  61.  
  62.   # wait for the box to be destroyed
  63.   update idletask
  64.   grab $xfInputBox(toplevelName)
  65.   tkwait window $xfInputBox(toplevelName)
  66.  
  67.   return $xfInputBox($xfInputBox(toplevelName),inputOne)
  68. }
  69.  
  70. proc XFInputBoxMulti {{xfInputBoxMessage "Input box:"} {xfInputBoxCommandOk ""} {xfInputBoxCommandCancel ""} {xfInputBoxGeometry 350x150} {xfInputBoxTitle "Input box"}} {# xf ignore me 5
  71. ##########
  72. # Procedure: XFInputBoxMulti
  73. # Description: show input box with one text line
  74. # Arguments: {xfInputBoxMessage} - message to display
  75. #            {xfInputBoxCommandOk} - the command to call after ok
  76. #            {xfInputBoxCommandCancel} - the command to call after cancel
  77. #            {xfInputBoxGeometry} - the geometry for the window
  78. #            {xfInputBoxTitle} - the title for the window
  79. # Returns: The entered text
  80. # Sideeffects: none
  81. # Notes: there exist also a function called:
  82. #          XFInputBoxOne - to enter one line text
  83. ##########
  84. #
  85. # global xfInputBox(activeBackground) - active background color
  86. # global xfInputBox(activeForeground) - active foreground color
  87. # global xfInputBox(anchor) - anchor for message box
  88. # global xfInputBox(background) - background color
  89. # global xfInputBox(erase) - erase previous text
  90. # global xfInputBox(font) - message font
  91. # global xfInputBox(foreground) - foreground color
  92. # global xfInputBox(justify) - justify for message box
  93. # global xfInputBox(scrollActiveForeground) - scrollbar active background color
  94. # global xfInputBox(scrollBackground) - scrollbar background color
  95. # global xfInputBox(scrollForeground) - scrollbar foreground color
  96. # global xfInputBox(scrollSide) - side where scrollbar is located
  97. # global xfInputBox(toplevelName) - the toplevel name
  98. # global xfInputBox(toplevelName,inputMulti) - the text in the text widget
  99.  
  100.   global xfInputBox
  101.  
  102.   if {"$xfInputBoxGeometry" == ""} {
  103.     set xfInputBoxGeometry 350x150
  104.   }
  105.   if {$xfInputBox(erase)} {
  106.     set xfInputBox($xfInputBox(toplevelName),inputMulti) ""
  107.   } {
  108.     if {![info exists xfInputBox($xfInputBox(toplevelName),inputMulti)]} {
  109.       set xfInputBox($xfInputBox(toplevelName),inputMulti) ""
  110.     }
  111.   }
  112.   XFInputBoxInternal $xfInputBoxMessage $xfInputBoxCommandOk $xfInputBoxCommandCancel $xfInputBoxGeometry $xfInputBoxTitle 2
  113.  
  114.   # wait for the box to be destroyed
  115.   update idletask
  116.   grab $xfInputBox(toplevelName)
  117.   tkwait window $xfInputBox(toplevelName)
  118.  
  119.   return $xfInputBox($xfInputBox(toplevelName),inputMulti)
  120. }
  121.  
  122. ##########
  123. # Procedure: XFInputBoxInternal
  124. # Description: show input box internal
  125. # Arguments: xfInputBoxMessage - the text to display
  126. #            xfInputBoxCommandOk - the command to call after ok
  127. #            xfInputBoxCommandCancel - the command to call after cancel
  128. #            xfInputBoxGeometry - the geometry for the window
  129. #            xfInputBoxTitle - the title for the window
  130. #            lineNum - number of lines
  131. # Returns: none
  132. # Sideeffects: none
  133. ##########
  134. proc XFInputBoxInternal {xfInputBoxMessage xfInputBoxCommandOk xfInputBoxCommandCancel xfInputBoxGeometry xfInputBoxTitle lineNum} {# xf ignore me 6
  135.   global xfInputBox
  136.  
  137.   set tmpButtonOpt ""
  138.   set tmpFrameOpt ""
  139.   set tmpMessageOpt ""
  140.   set tmpScaleOpt ""
  141.   set tmpScrollOpt ""
  142.   if {"$xfInputBox(activeBackground)" != ""} {
  143.     append tmpButtonOpt "-activebackground \"$xfInputBox(activeBackground)\" "
  144.   }
  145.   if {"$xfInputBox(activeForeground)" != ""} {
  146.     append tmpButtonOpt "-activeforeground \"$xfInputBox(activeForeground)\" "
  147.   }
  148.   if {"$xfInputBox(background)" != ""} {
  149.     append tmpButtonOpt "-background \"$xfInputBox(background)\" "
  150.     append tmpFrameOpt "-background \"$xfInputBox(background)\" "
  151.     append tmpMessageOpt "-background \"$xfInputBox(background)\" "
  152.   }
  153.   if {"$xfInputBox(font)" != ""} {
  154.     append tmpButtonOpt "-font \"$xfInputBox(font)\" "
  155.     append tmpMessageOpt "-font \"$xfInputBox(font)\" "
  156.   }
  157.   if {"$xfInputBox(foreground)" != ""} {
  158.     append tmpButtonOpt "-foreground \"$xfInputBox(foreground)\" "
  159.     append tmpMessageOpt "-foreground \"$xfInputBox(foreground)\" "
  160.   }
  161.   if {"$xfInputBox(scrollActiveForeground)" != ""} {
  162.     append tmpScrollOpt "-activeforeground \"$xfInputBox(scrollActiveForeground)\" "
  163.   }
  164.   if {"$xfInputBox(scrollBackground)" != ""} {
  165.     append tmpScrollOpt "-background \"$xfInputBox(scrollBackground)\" "
  166.   }
  167.   if {"$xfInputBox(scrollForeground)" != ""} {
  168.     append tmpScrollOpt "-foreground \"$xfInputBox(scrollForeground)\" "
  169.   }
  170.  
  171.   XFTmpltToplevel $xfInputBox(toplevelName) "$xfInputBoxGeometry" "$xfInputBoxTitle"
  172.  
  173.   message $xfInputBox(toplevelName).message1 \
  174.     -anchor "$xfInputBox(anchor)" \
  175.     -justify "$xfInputBox(justify)" \
  176.     -relief raised \
  177.     -text "$xfInputBoxMessage"
  178.   catch "$xfInputBox(toplevelName).message1 config $tmpMessageOpt"
  179.  
  180.   set xfTmpWidth \
  181.     [string range $xfInputBoxGeometry 0 [expr [string first x $xfInputBoxGeometry]-1]]
  182.   if {"$xfTmpWidth" != ""} {
  183.     # set message size
  184.     catch "$xfInputBox(toplevelName).message1 configure \
  185.       -width [expr $xfTmpWidth-10]"
  186.   } {
  187.     $xfInputBox(toplevelName).message1 configure \
  188.       -aspect 1500
  189.   }
  190.  
  191.   frame $xfInputBox(toplevelName).frame0 \
  192.     -borderwidth 0 \
  193.     -relief raised
  194.   catch "$xfInputBox(toplevelName).frame0 config $tmpFrameOpt"
  195.  
  196.   frame $xfInputBox(toplevelName).frame1 \
  197.     -borderwidth 0 \
  198.     -relief raised
  199.   catch "$xfInputBox(toplevelName).frame1 config $tmpFrameOpt"
  200.  
  201.   if {$lineNum == 1} {
  202.     scrollbar $xfInputBox(toplevelName).frame1.hscroll \
  203.       -orient "horizontal" \
  204.       -relief raised \
  205.       -command "$xfInputBox(toplevelName).frame1.input view"
  206.     catch "$xfInputBox(toplevelName).frame1.hscroll config $tmpScrollOpt"
  207.  
  208.     entry $xfInputBox(toplevelName).frame1.input \
  209.       -relief raised \
  210.       -scrollcommand "$xfInputBox(toplevelName).frame1.hscroll set"
  211.     catch "$xfInputBox(toplevelName).frame1.input config $tmpMessageOpt"
  212.  
  213.     $xfInputBox(toplevelName).frame1.input insert 0 \
  214.       $xfInputBox($xfInputBox(toplevelName),inputOne)
  215.     
  216.     # bindings
  217.     bind $xfInputBox(toplevelName).frame1.input <Return> "
  218.       global xfInputBox
  219.       set xfInputBox($xfInputBox(toplevelName),inputOne) \[$xfInputBox(toplevelName).frame1.input get\]
  220.       if {\"\[info commands XFDestroy\]\" != \"\"} {
  221.         catch {XFDestroy $xfInputBox(toplevelName)}
  222.       } {
  223.         catch {destroy $xfInputBox(toplevelName)}
  224.       }
  225.       $xfInputBoxCommandOk"
  226.     
  227.     # packing
  228.     pack append $xfInputBox(toplevelName).frame1 \
  229.                 $xfInputBox(toplevelName).frame1.hscroll {bottom fill} \
  230.                 $xfInputBox(toplevelName).frame1.input {top fill expand}
  231.   } {
  232.     text $xfInputBox(toplevelName).frame1.input \
  233.       -relief raised \
  234.       -wrap none \
  235.       -borderwidth 2 \
  236.       -yscrollcommand "$xfInputBox(toplevelName).frame1.vscroll set"
  237.     catch "$xfInputBox(toplevelName).frame1.input config $tmpMessageOpt"
  238.  
  239.     scrollbar $xfInputBox(toplevelName).frame1.vscroll \
  240.       -relief raised \
  241.       -command "$xfInputBox(toplevelName).frame1.input yview"
  242.     catch "$xfInputBox(toplevelName).frame1.vscroll config $tmpScrollOpt"
  243.  
  244.     $xfInputBox(toplevelName).frame1.input insert 1.0 \
  245.       $xfInputBox($xfInputBox(toplevelName),inputMulti)
  246.  
  247.     # bindings
  248.     bind $xfInputBox(toplevelName).frame1.input <Control-Return> "
  249.       global xfInputBox
  250.       set xfInputBox($xfInputBox(toplevelName),inputMulti) \[$xfInputBox(toplevelName).frame1.input get 1.0 end\]
  251.       if {\"\[info commands XFDestroy\]\" != \"\"} {
  252.         catch {XFDestroy $xfInputBox(toplevelName)}
  253.       } {
  254.         catch {destroy $xfInputBox(toplevelName)}
  255.       }
  256.       $xfInputBoxCommandOk"
  257.     bind $xfInputBox(toplevelName).frame1.input <Meta-Return> "
  258.       global xfInputBox
  259.       set xfInputBox($xfInputBox(toplevelName),inputMulti) \[$xfInputBox(toplevelName).frame1.input get 1.0 end\]
  260.       if {\"\[info commands XFDestroy\]\" != \"\"} {
  261.         catch {XFDestroy $xfInputBox(toplevelName)}
  262.       } {
  263.         catch {destroy $xfInputBox(toplevelName)}
  264.       }
  265.       $xfInputBoxCommandOk"
  266.  
  267.     # packing
  268.     pack append $xfInputBox(toplevelName).frame1 \
  269.                 $xfInputBox(toplevelName).frame1.vscroll "$xfInputBox(scrollSide) filly" \
  270.                 $xfInputBox(toplevelName).frame1.input {left fill expand}
  271.   }
  272.   
  273.   button $xfInputBox(toplevelName).frame0.button0 \
  274.     -text "OK" \
  275.     -command "
  276.       global xfInputBox
  277.       if {$lineNum == 1} {
  278.         set xfInputBox($xfInputBox(toplevelName),inputOne) \[$xfInputBox(toplevelName).frame1.input get\]
  279.       } {
  280.         set xfInputBox($xfInputBox(toplevelName),inputMulti) \[$xfInputBox(toplevelName).frame1.input get 1.0 end\]
  281.       }
  282.       if {\"\[info commands XFDestroy\]\" != \"\"} {
  283.         catch {XFDestroy $xfInputBox(toplevelName)}
  284.       } {
  285.         catch {destroy $xfInputBox(toplevelName)}
  286.       }
  287.       $xfInputBoxCommandOk"
  288.   catch "$xfInputBox(toplevelName).frame0.button0 config $tmpButtonOpt"
  289.  
  290.   button $xfInputBox(toplevelName).frame0.button1 \
  291.     -text "Cancel" \
  292.     -command "
  293.       global xfInputBox
  294.       if {$lineNum == 1} {
  295.         set xfInputBox($xfInputBox(toplevelName),inputOne) \"\"
  296.       } {
  297.         set xfInputBox($xfInputBox(toplevelName),inputMulti) \"\"
  298.       }
  299.       if {\"\[info commands XFDestroy\]\" != \"\"} {
  300.         catch {XFDestroy $xfInputBox(toplevelName)}
  301.       } {
  302.         catch {destroy $xfInputBox(toplevelName)}
  303.       }
  304.       $xfInputBoxCommandCancel"
  305.   catch "$xfInputBox(toplevelName).frame0.button1 config $tmpButtonOpt"
  306.  
  307.   pack append $xfInputBox(toplevelName).frame0 \
  308.               $xfInputBox(toplevelName).frame0.button0 {left fill expand} \
  309.               $xfInputBox(toplevelName).frame0.button1 {left fill expand}
  310.  
  311.   pack append $xfInputBox(toplevelName) \
  312.               $xfInputBox(toplevelName).frame0 {bottom fill} \
  313.               $xfInputBox(toplevelName).frame1 {bottom fill expand} \
  314.               $xfInputBox(toplevelName).message1 {top fill}
  315. }
  316.  
  317. # eof
  318.  
  319.